package com.example.springbootvuetest.Utils;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import java.util.Collections;

import static com.baomidou.mybatisplus.generator.FastAutoGenerator.*;

public class CodeGenerator {

    public static void main(String[] args) {
        String[] tableNames = new String[]{"sh_order","sh_address", "sh_admin", "sh_favorite", "sh_idle_item", "sh_message", "sh_order_address"};
        for (String table : tableNames) {
            generate(table);
        }
    }
    private static void generate(String table) {
        create("jdbc:mysql://localhost:3306/second_hand_trading?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8", "root", "123")
                .globalConfig(builder -> {
                    builder.author("shuoye") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D:\\IDEAspace\\springboot-vue-test\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.example.springbootvuetest") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\IDEAspace\\springboot-vue-test\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableLombok()
                            .idType(IdType.AUTO);
                    builder.mapperBuilder()
                            .enableMapperAnnotation().build();
                    builder.controllerBuilder()
                            .enableHyphenStyle()// 开启驼峰转连字符
                            .enableRestStyle();  // 开启生成@RestController 控制器
                    builder.addInclude(table) // 设置需要生成的表名
                            .addTablePrefix("sh_"); // 设置过滤表前缀
                })
                .execute();
    }
}
